Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

519
Visualizações
How to use [FromBody] and [FromQuery] attribute at the same time?

In the post request,I need to get the parameters from the query string at the same time.This is my code,but can't work


 [HttpPost("test")]
 public string Test(TestRequest request)
 {
      //TODO  ...
 }


    public class TestRequest
    {
        [FromHeader(Name = "id")]
        public string Id { get; set; }

        [FromQuery(Name = "traceId")]
        public string Trace { get; set; }

        public string Name { get; set; }

        [MaxLength(4)]
        public string Mark { get; set; }

        [Range(18, 35)]
        public int Age { get; set; }
    }

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You have to put the different parameters in the method signatur, so it would be something like

[HttpPost("test/{traceId}")] // Note the query parameter 
public string Test(
    [FromHeader(Name = "id")]string id,
    [FromQuery(Name = "traceId")]string trace,
    [FromBody]Request request
    )
{
    // TODO...
}

public class Request
{
    public string Name { get; set; }
    public string Mark { get; set; }
    public int Age { get; set; }
}

bit depending on how your actual request looks like. This would read a Request-Object form the body, the id from the header and the traceId from the query.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda